package com.maple.phoneward.service;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;

import com.maple.phoneward.constants.Constants;
import com.maple.phoneward.receiver.AppBroadcastReceiver;
import com.maple.phoneward.utils.Logger;

/**
 * SystemService.java
 * 
 * @author YaJian Qiu
 * @time 2013-3-30 上午9:55:25<br>
 *       本类描述：系统服务
 * 
 */
public class SystemService extends Service {

	private static final String TAG = "SystemService";
	private AppBroadcastReceiver receiver;

	class MyBind extends Binder {

	}

	@Override
	public IBinder onBind(Intent intent) {
		return new MyBind();
	}

	@Override
	public void onCreate() {
		Logger.d(TAG, "系统服务创建");
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Logger.d(TAG, "在系统服务中执行命令");
		// 动态注册短信广播接收器
		IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
		filter.setPriority(Constants.INTEGER_MAX_VALUE);
		receiver = new AppBroadcastReceiver();
		registerReceiver(receiver, filter);

		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		Logger.d(TAG, "系统服务销毁");
		unregisterReceiver(receiver);
	}

}
